//
//  LYHFastFoodCell.m
//  05-用storyboard自定义cell
//
//  Created by LYH on 2016/12/19.
//  Copyright © 2016年 LYH. All rights reserved.
//

#import "LYHFastFoodCell.h"
#import "LYHFastFoodModel.h"
#import "Masonry.h"


@interface LYHFastFoodCell ()

@property (nonatomic,strong) UIImageView *iconImageView;
@property (nonatomic,strong) UILabel *priceLabel;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *buyCountLabel;
@end

@implementation LYHFastFoodCell

//重写init方法,添加子控件
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    //添加子控件
    UIImageView *iconImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:iconImageView];
    self.iconImageView = iconImageView;
    
    UILabel *priceLabel = [[UILabel alloc]init];
    //    priceLabel.font = [UIFont systemFontOfSize:15];
    priceLabel.textColor = [UIColor orangeColor];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UILabel *titleLabel = [[UILabel alloc]init];
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *buyCountLabel = [[UILabel alloc]init];
    buyCountLabel.font = [UIFont systemFontOfSize:13];
    buyCountLabel.textColor = [UIColor lightGrayColor];
    buyCountLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:buyCountLabel];
    self.buyCountLabel = buyCountLabel;
    
    return self;
}

-(void)layoutSubviews
{
    CGFloat space = 10;
    //icon
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(space);
        make.left.equalTo(self.contentView.mas_left).offset(space);
        make.width.equalTo(@80);
        make.height.equalTo(self.contentView.mas_height).offset(-20);
    }];
    //title
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView.mas_top);
        make.left.equalTo(self.iconImageView.mas_right).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.height.equalTo(@20);
    }];
    //price
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
        make.width.equalTo(@50);
        make.height.equalTo(@15);
    }];
    //buyCount
    [self.buyCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.bottom.equalTo(self.priceLabel.mas_bottom);
        make.top.equalTo(self.priceLabel.mas_top);
        make.width.equalTo(@150);
    }];

}

-(void)setFastFoodModel:(LYHFastFoodModel *)fastFoodModel{
    _fastFoodModel = fastFoodModel;
    self.iconImageView.image = [UIImage imageNamed:fastFoodModel.icon];
    self.titleLabel.text = fastFoodModel.title;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",fastFoodModel.price];
    self.buyCountLabel.text = [NSString stringWithFormat:@"%@人已购买",fastFoodModel.buyCount];
}


@end
